home *** CD-ROM | disk | FTP | other *** search
- #include <stdio.h>
- #include <method\methodSx.h>
- #include <sxlib.h>
- #include <iocslib.h>
- #include "pcm8pp.h"
- #include "spsx.h"
-
- uchar *pcPcmData[2]; /* PCMバッファ */
-
- int iIsPlaying; /* 再生中か? */
-
- int iPlayMode; /* 再生種別 PLAY_NORMAL */
- /* PLAY_RANDOM */
-
- int iAddPlayFile( uchar *);
- int iReadSoundList( uchar * );
- int iAddPlayAFile( uchar *,uchar *);
-
- remote stPlayList_t stPlayList;
-
- extern int iPlayTrack;
- extern uchar *pcPlayTitle;
-
- extern job_t jobPcmPlay;
- extern job_t jobPlayCtrl;
-
- extern rectImg **pImgRandomButton; /* ランダムボタン */
- extern rectImg **pImgDisRndButton; /* ランダム取り消しボタン */
- extern rectImg **pImgPushRndButton; /* ランダムボタンを押した状態 */
- extern rectImg **pImgPushDisRndButton; /* ランダム取り消しボタンを押した状態 */
-
- extern rectImg **pImageH[5]; /* イメージボタン配列(通常ボタン) */
- extern rectImg **pImageL[5]; /* (押されている時) */
-
- extern window_t mainWin; /* ウインドウ定義 */
-
- extern m_picbtn_t stCtrlButton;
-
- extern method_t mCtrlButton;
-
-
- void main(int argc, uchar *argv[])
- {
- int program_loop = true;
- int iResult;
- order_t stOrder;
- int iPauseFlag; /* 一時停止中:1 通常:0 */
- uchar *pcPtr;
- int iTaskID;
- handle hHandle;
- tsevent tsEv;
- int i;
- int iCheck;
- uchar **ppcPtr; /* TRAP#2 のアドレス格納のためのポインタポインタ */
-
- iPauseFlag = 0;
- iIsPlaying = 0;
-
-
- iPlayTrack = 0;
- pcPlayTitle = NULL;
-
- /* PCM8++の常駐検査 */
- iResult = B_SUPER(0); /* スーパーバイザモードへ */
- ppcPtr = (uchar **)0x88; /* TRAP#2のアドレス */
- pcPtr = *ppcPtr - 16; /* TRAP#2 - 16 に "PCM8++"と入っているはず */
- iCheck = memcmp(pcPtr,"PCM8++",6);
- B_SUPER(iResult); /* スーパーバイザモードから抜ける */
-
- if ( iCheck != 0 ) { /* PCM8++がなければ終了 */
- DMError(1,"PCM8++が常駐してません!");
- exit(1);
- }
-
-
- iTaskID = TSFindOwn();
- if ( iTaskID > 0 ) {
- exit(1);
- }
-
- iResult = iReadResFile(); /* リソースファイルを読み込む */
-
- if ( iResult != 0 ) {
- if (iResult == 1) {
- iCloseResFile();
- }
- exit(1);
- }
-
- ChainMethod( &mainWin, &mCtrlButton );
-
-
- if (OpenWindow(&mainWin, -1)) {
- DMError( 1, "ウインドウを開けません!!" );
- iCloseResFile();
- exit(1);
- }
-
-
- stPlayList.pstPlayList = (stPlayListItem_t *)malloc( sizeof(stPlayListItem_t[100]));
-
- if ( stPlayList.pstPlayList == NULL ) {
- DMError(1,"メモリが確保できません");
- iCloseResFile();
- exit(1);
- }
-
- stPlayList.iMusicCount = 0;
- stPlayList.iPlayCount = 0;
- stPlayList.iPlayingNo = 0;
-
- if ( argc >= 2 ) {
- for ( i = 1; i < argc; i++ ) {
- if ( argv[i][0] != '-' && argv[i][0] != '/' ) {
- iAddPlayFile( argv[i] );
- }
- }
- }
-
- pcPcmData[0]=(uchar *)malloc(PCM_BUF_SIZE);
- pcPcmData[1]=(uchar *)malloc(PCM_BUF_SIZE);
-
- if (pcPcmData[0]==NULL || pcPcmData[1]==NULL) {
- DMError(1,"メモリが確保できません");
- iCloseResFile();
- exit(1);
- }
-
- srand(time(NULL));
-
- iPlayMode = PLAY_NORMAL;
-
- iIsPlaying = 1;
-
- ChainJob(&jobPlayCtrl);
- SetIntervalJob( &jobPlayCtrl,20 );
-
- while (program_loop) { /* メインループ */
-
- stOrder.ev = MayIHelpYou();
-
- switch (stOrder.ev) { /* Q:ユーザーさん、何がしたいのですか? */
- case EV_CLOSEALL: /* A:全部閉じて欲しいそうです */
- case EV_CLOSEWIN: /* A:あるウインドウを閉じて欲しいそうです */
- program_loop = false; /* ウインドウは一つしかないから結局終了 */
- default:
- if ( stOrder.mth == &mCtrlButton ) {
- switch (stCtrlButton.pValue) {
-
- case 1: /* 再生・一時停止ボタンの処理 */
-
- if ( iPauseFlag == 1 ) { /* 一時停止解除 */
- AwakeJob(&jobPlayCtrl);
- iPauseFlag = 0;
- }
- else if ( iIsPlaying == 1 ) { /* 一時停止 */
- SleepJob(&jobPlayCtrl);
- iPauseFlag = 1;
- }
- else {
- iIsPlaying = 1;
-
- ChainJob(&jobPlayCtrl);
- SetIntervalJob( &jobPlayCtrl,20 );
- }
-
- break;
-
- case 2: /* 停止ボタンの処理 */
- iPauseFlag = 0;
- UnchainJob();
-
- break;
-
- case 3:
- if ( iIsPlaying == 1 ) {
- if ( stPlayList.iPlayCount < stPlayList.iMusicCount ) {
- if ( iPauseFlag == 1 ) {
- AwakeJob(&jobPlayCtrl);
- iPauseFlag = 0;
- }
- UnchainAJob( &jobPcmPlay );
- }
- }
- else {
- if ( iPlayTrack < stPlayList.iMusicCount ) {
- stPlayList.iPlayingNo++;
- stPlayList.iPlayCount++;
- pcPlayTitle = stPlayList.pstPlayList[iPlayTrack].acTitle;
- iPlayTrack++;
- iDrawTitle();
- iDrawTrack();
- }
- }
- break;
-
- case 4:
- if ( iIsPlaying == 1 ) {
- if ( stPlayList.iPlayCount >= 2 && iPlayMode == PLAY_NORMAL ) {
- stPlayList.iPlayingNo -= 2;
- stPlayList.iPlayCount -= 2;
-
- if ( iPauseFlag == 1 ) {
- AwakeJob(&jobPlayCtrl);
- iPauseFlag = 0;
- }
- UnchainAJob( &jobPcmPlay );
- }
- }
- else {
- if ( iPlayTrack > 2 ) {
- stPlayList.iPlayingNo--;
- stPlayList.iPlayCount--;
- pcPlayTitle = stPlayList.pstPlayList[iPlayTrack-2].acTitle;
- iPlayTrack--;
- iDrawTitle();
- iDrawTrack();
- }
- }
- break;
-
- case 5:
- iPauseFlag = 0;
-
- if ( iPlayMode == PLAY_NORMAL ) {
- UnchainJob();
-
- iPlayMode = PLAY_RANDOM;
- iDrawTrack();
-
- iIsPlaying = 1;
-
- ChainJob(&jobPlayCtrl);
- SetIntervalJob( &jobPlayCtrl,20 );
- }
- else {
-
- iPlayMode = PLAY_NORMAL;
- iDrawTrack();
-
- stPlayList.iPlayCount = stPlayList.iPlayingNo;
-
- }
-
-
- break;
-
- default:
- break;
- }
- }
- }
-
- }
-
- UnchainJob();
-
- free(stPlayList.pstPlayList);
-
- free( pcPcmData[0] );
- free( pcPcmData[1] );
-
- CloseWindow(&mainWin); /* ウインドウを閉じる */
-
- iCloseResFile();
-
-
- }
-
- int iAddPlayFile( uchar *pcFile )
- {
- char acExt[4];
- int iLen;
- int iTitleDrawFlag;
-
- if ( stPlayList.iMusicCount == 0 ) { /* いままで曲が登録されていないとき */
- iTitleDrawFlag = 1; /* 登録した曲名を表示する必要がある */
- }
- else {
- iTitleDrawFlag = 0;
- }
- iLen = strlen( pcFile );
- iLen -= 3;
- strcpy( acExt, pcFile + iLen );
-
- if ( SXStrCmp( acExt, "SLT", 3 ) == 0 ) {
- iReadSoundList( pcFile);
- }
- else {
- iAddPlayAFile( pcFile,NULL );
- }
-
- if ( iTitleDrawFlag == 1 && stPlayList.iMusicCount > 0 ) {
- iPlayTrack = 1;
- pcPlayTitle = stPlayList.pstPlayList[0].acTitle;
- iDrawTitle();
- }
-
- iDrawTrack();
- }
-
- int iReadSoundList( uchar *pcFile )
- {
- // int iHandle;
-
- uchar acTemp[256];
-
- uchar acFileName[256]; /* ファイル名 */
- uchar acTitle[32]; /* 曲名 */
-
- int i;
- int j;
-
- FILE *pFile;
-
-
- // iHandle = TSOpen( pcFile, _O_RDONLY );
- pFile = fopen( pcFile, "r" );
-
- if ( pFile == NULL ) { /* オープン失敗の場合 */
-
- DMError(1,"OPEN ERROR!!");
- return 1;
- }
-
- while ( fgets( acTemp, sizeof(acTemp), pFile ) != NULL ) {
- i = 0;
-
- /* ファイル名取得 */
- while( acTemp[i] != '\n' && acTemp[i] != '\t' && acTemp[i] != '\0' ) {
- acFileName[i] = acTemp[i];
- i++;
- }
-
- acFileName[i] = '\0';
-
- while( acTemp[i] == '\t' ) {
- i++;
- }
-
- j = 0;
-
- while( acTemp[i] != '\n' && acTemp[i] != '\0' && j < 30 ) {
- acTitle[j] = acTemp[i];
- j++;
- i++;
- }
- acTitle[j] = '\0';
-
-
- if ( acFileName[0] != '\0' ) {
- if ( j > 0 ) {
- iAddPlayAFile( acFileName, acTitle );
- }
- else {
- iAddPlayAFile( acFileName, NULL );
- }
- }
- }
-
- fclose( pFile );
-
- // TSClose( iHandle );
- }
-
-
- int iAddPlayAFile( uchar *pcFile, uchar *pcTitle )
- {
- int iAddPoint;
- uchar *pcPtr;
- int iType;
- uchar acExt[4];
- int iLen;
-
- iAddPoint = stPlayList.iMusicCount;
-
- if ( iAddPoint >= 99 ) {
- DMError( 1,"これ以上登録できません!");
- return -1;
- }
-
- iLen = strlen( pcFile );
- iLen -= 3;
- strcpy( acExt, pcFile + iLen );
-
- iType = 0;
-
- if (SXStrCmp( acExt, "S44", 3 ) == 0 ) {
- iType = TYPE_S44;
- }
-
- if ( iType != 0 ) {
- stPlayList.iMusicCount++;
-
- stPlayList.pstPlayList[iAddPoint].iPlayFlag = 0;
- stPlayList.pstPlayList[iAddPoint].iFileType = iType;
-
- strcpy(stPlayList.pstPlayList[iAddPoint].acFileName, pcFile);
-
- if ( pcTitle == NULL ) {
- pcPtr = stPlayList.pstPlayList[iAddPoint].acTitle;
- *pcPtr = (uchar)iFileName2Title( pcFile, pcPtr+1);
- }
- else {
- pcPtr = stPlayList.pstPlayList[iAddPoint].acTitle;
- *pcPtr = (uchar)strlen(pcTitle);
- strcpy(pcPtr+1,pcTitle);
- }
- }
- }
-
- int iFileDrop()
- {
- uchar acFile[256];
- int iRet;
-
- iRet = ULGetDroppedFile( acFile );
-
- TSEndDrag(0);
-
- if ( iRet > 0 ) {
- iAddPlayFile(acFile);
- }
-
- return 0;
- }
-
- int iFileName2Title( uchar *pcFileName, uchar *pcTitle )
- {
- uchar *pcPtr;
- int iLen;
- int i;
- int iExtPoint;
- int iCutSize;
-
- iLen = strlen(pcFileName);
- pcPtr = pcFileName;
-
-
- iCutSize = 0;
- iExtPoint = 0;
-
- for ( i = 0; i < iLen; i++ ) {
- if ( (pcPtr[i] > 0x80 && pcPtr[i] < 0x9f) ||
- (pcPtr[i] > 0xe0 && pcPtr[i] < 0xff) ) {
- i++;
- }
- else {
- if (pcPtr[i] == '\\' || pcPtr[i] == '/' || pcPtr[i] == ':' ) {
- iCutSize = i+1;
- }
- if (pcPtr[i] == '.') {
- iExtPoint = i;
- }
- }
- }
-
- if ( iExtPoint < iCutSize ) {
- iExtPoint = iLen;
- }
-
-
- for ( i = iCutSize; i < iExtPoint; i++ ) {
- pcTitle[i-iCutSize] = pcPtr[i];
- }
-
- pcTitle[i-iCutSize] = '\0';
-
- return (i - iCutSize);
- }